package texture;

import javax.vecmath.Color3f;

public class CheckerboardTexture extends Texture {

	private int numRows, numColumns;
	private Color3f colorOne, colorTwo;

	public CheckerboardTexture(int numRows, int numColumns, Color3f colorOne,
			Color3f colorTwo) {
		super();
		this.numRows = numRows;
		this.numColumns = numColumns;
		this.colorOne = colorOne;
		this.colorTwo = colorTwo;
	}

	@Override
	public Color3f getColor(float widthPercent, float depthPercent) {
		int row = (int) (depthPercent * this.numRows);
		int col = (int) (widthPercent * this.numColumns);
		if (this.isEven(row) && this.isEven(col)) {
			return colorOne;
		} else if (this.isEven(row) && !this.isEven(col)) {
			return colorTwo;
		} else if (!this.isEven(row) && this.isEven(col)) {
			return colorTwo;
		} else {
			return colorOne;
		}
	}

	private boolean isEven(int num) {
		return (num % 2) == 0;
	}

}
